package net.hn.hnms.biz.sewage.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.hn.hnms.biz.sewage.entity.CalculationVo;
import net.hn.hnms.biz.sewage.entity.SewageIndexEntity;
import net.hn.hnms.biz.sewage.entity.SewageIndexParameter;
import net.hn.hnms.biz.sewage.service.SewageIndexService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @author 智呈物联 nzw
 * @date 2022/9/23
 */
@RestController
@RequestMapping("safety/sewage/sewageIndex")
public class SewageIndexController {

    private SewageIndexService sewageIndexService;

    @Autowired
    public void setSewageIndexService(SewageIndexService sewageIndexService) {
        this.sewageIndexService = sewageIndexService;
    }

    @ApiOperation("污水添加")
    @PostMapping("/add")
    public R add(@RequestBody SewageIndexEntity sewageIndexEntity) {
        sewageIndexEntity = sewageIndexService.add(sewageIndexEntity);
        if (sewageIndexEntity == null) {
            return R.fail("已存在该日期报表，无需再次添加");
        }
        return R.ok(sewageIndexEntity);
    }

    @ApiOperation("污水列表")
    @GetMapping("/domesticSewage/pageList")
    @AutoSetMineCode
    public R domesticSewagePageList(PageQuery pageQuery, SewageIndexParameter sewageIndexParameter) {
        return R.ok(sewageIndexService.domPageList(pageQuery, sewageIndexParameter));
    }

    @ApiOperation("污水上班及总量统计")
    @GetMapping("calculation")
    public R<CalculationVo> calculation(@ApiParam("日期") String date, @ApiParam("班次  1，2，3") Integer shit, @ApiParam("工业（2）还是生活（1）") String sewageType) {
        try {
            return R.ok(sewageIndexService.calculation(date, shit, sewageType));
        } catch (ParseException e) {
            return R.fail("时间解析错误");
        }
    }

    @ApiOperation("污水删除")
    @GetMapping("/delete")
    public R delete(Long id) {
        sewageIndexService.delete(id);
        return R.ok();
    }
}
